import Vue from 'vue';
import VueRouter from 'vue-router';
// import Config from '@/api/config.js';
import store from '@/store';
import HomeView from '@/views/home.vue';
import WorkBench from "@/views/ViewsMain/Main/page/WorkBench/App.vue";
import Analysis from "@/views/ViewsMain/Main/page/Analysis/App.vue";
import RoleList from '@/views/ViewsMain/Main/page/RoleList/App.vue';
import FormPage from '@/views/ViewsMain/Main/page/FormPage/App.vue';
import PersonalPage from "@/views/ViewsMain/Main/page/PersonalPage/App.vue";
import ManagePage from '@/views/ViewsMain/Main/page/ManagePage/App.vue';
import LoginPage from '@/components/LoginPage/App.vue';
import NotFoundComponent from '@/components/NotFoundComponent/App.vue';

Vue.use(VueRouter);

const routes = [

  {
    path: '/',
    redirect: '/login',

  },
  {
    path: '*',
    component: NotFoundComponent
  },
  {
    path: '/login',
    name: 'loginlll',
    component: LoginPage
  },
  {
    path: '/home',
    name: 'home',
    redirect: '/home/WorkBench',
    component: HomeView,
    // route level code-splitting
    // this generates a separate chunk (home.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    // component: () => import(/* webpackChunkName: "home" */ '@/views/homeView.vue')
    children: [
      {
        path: 'workbench',
        component: WorkBench,
      },
      {
        path: 'Analysis',
        component: Analysis,
      },
      {
        path: 'RoleList',
        component: RoleList
      },
      {
        path: 'FormPage',
        component: FormPage
      },
      {
        path: 'PersonalPage',
        component: PersonalPage
      },
      {
        path: 'ManagePage',
        component: ManagePage
      }
    ]

  },

];

const router = new VueRouter({
  mode: 'hash',
  routes
});

router.beforeEach((to, from, next) => {
  store.commit('cms_tokenSync');
  const token = store.getters.token;
  console.log(token);
  // 默认导航到login中
  if (to.path !== "/login") {
    // token 验证放行
    if (token === '1234567890') {
      next();
    } else {
      next('/login');
    }
  } else {
    console.log('寂寞');
    next();
  }
});
export default router;
